package com.jgdt.jgdtkasannong_university_gene_backend.common.response;



import com.jgdt.jgdtkasannong_university_gene_backend.common.enums.SystemCodeEnums;
import io.swagger.v3.oas.annotations.media.Schema;

import java.io.Serializable;
/**
 * @description: 基础前台传输类
 * @author: huangAn
 * @createDate: 2025/04/18
 */
@Schema(description = "响应")
public class ResultVo<T> implements Serializable {

    /**
     * @Fields serialVersionUID :
     */
    private static final long serialVersionUID = -8205320217851510589L;
    @Schema(description = "响应编码（0成功；-1失败）")
    private String code;
    @Schema(description = "返回消息")
    private String message;
    @Schema(description = "返回数据")
    private T dataResult;

    public ResultVo() {
    }

    public ResultVo(int code, String message, T obj) {
        this.code = code + "";
        this.message = message;
        this.dataResult = obj;
    }

    public static ResultVo<String> fail(String msg) {
        ResultVo<String> result = new ResultVo<>();
        result.setCode(SystemCodeEnums.FAIL.getKey());
        result.setMessage(msg);
        return result;
    }

    public static  <T> ResultVo<T> failCustomize(String code,String msg) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

    public static ResultVo<String> success() {
        ResultVo<String> result = new ResultVo<>();
        result.setCode(SystemCodeEnums.SUCCESS.getKey());
        result.setMessage(SystemCodeEnums.SUCCESS.getMsg());
        return result;
    }

    public static ResultVo<String> success(String dataResult) {
        ResultVo<String> result = new ResultVo<>();
        result.setCode(SystemCodeEnums.SUCCESS.getKey());
        result.setDataResult(dataResult);
        result.setMessage(SystemCodeEnums.SUCCESS.getMsg());
        return result;
    }

    public static <T> ResultVo<T> success(T obj, String msg) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(SystemCodeEnums.SUCCESS.getKey());
        result.setDataResult(obj);
        result.setMessage(msg);
        return result;
    }

    public static <T> ResultVo<T> success(T obj){
        ResultVo<T> result = new ResultVo<>();
        result.setCode(SystemCodeEnums
                .SUCCESS.getKey());
        result.setDataResult(obj);
        result.setMessage(SystemCodeEnums.SUCCESS.getMsg());
        return result;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getDataResult() {
        return dataResult;
    }

    public void setDataResult(T dataResult) {
        this.dataResult = dataResult;
    }

}
